<?php

	include("Commons.php");
	
	$action = param('ac');
	$abuseUser = getUser( param('username') );
	
	if ( $action=='validate-report' )
	{
		$reason = param('reason');
		$author = getCurrentUser();
		
		if ( $author!=-1 )
			$author = $author['id'];
		else
			$author = 0;
		
		if ( empty($reason) )
			$reasonerror = getTerm('abuse', 'empty_reason');
		
		if ( empty($reasonerror) )
		{
			query("INSERT INTO abuse (profile,author,reason) VALUES (${abuseUser[id]},$author,'$reason');");
			
			$_SESSION['message'] = getTerm('abuse', 'abuse_report_sent');
		}
		else
		{
			$action = 'report';
		}
	}
	
	pushNavigationItem( getTerm('abuse', 'report_abuse'), '/report/' );

	printHeader( getTerm('abuse', 'report_abuse') );
	
	$profileUrl = formatUrl("/profile/${abuseUser[username]}");

	if ( ! empty($_SESSION['message']) )
	{
		print "<div class=\"information\">". $_SESSION['message'] ."</div>";
		$_SESSION['message'] = '';
		
		print '<div id="return profile"><p>'. fill( getTerm('abuse', 'abuse_return') , $abuseUser['username'] , $profileUrl ) .'</p></div>';
	}
	
	if ( $action=='report' )
	{
		print '<div id="report">';
		
		print '<p>'. getTerm('abuse', 'reason_description') .'</p>';
		
		print '<form method="post" action="'. $_SERVER['REQUEST_URI'] .'">';
		print '<input type="hidden" name="ac" value="validate-report" />';
		print '<input type="hidden" name="username" value="'. $abuseUser['username'] .'" />';
		
		print '<div class="field'. (empty($reasonerror) ? '' : ' error') .'">';
		print '<label for="message">'. getTerm('abuse', 'reason') .'</label>';
		print '<textarea name="reason" id="reason">'. $reason .'</textarea>';
		print (empty($reasonerror) ? '' : "<div class=\"error-hint\">$reasonerror</div>");
		print '</div>';
		
		print '<input type="submit" value="'. getTerm('abuse', 'report') .'" /> ';
		print fill( getTerm('abuse', 'cancel') , $abuseUser['username'] , $profileUrl );
		
		print '</form>';
		print '</div>';
		
		print '<div id="abuse-description">';
		print '<h3>'. fill( getTerm('abuse', 'user_description') , $abuseUser['username'] ) .'</h3>';
		print '<p>'. $abuseUser['description'] .'</p>';
		print '</div>';
	}
	
	printFooter();

?>
